﻿using Sgr.Security.Permissions;

namespace Sgr.DataCategories
{
    /// <summary>
    /// 数据字典权限定义
    /// </summary>
    public class Permissions : IPermissionProvider
    {
        #region 数据字典权限

        /// <summary>
        /// 重置本地缓存权限
        /// </summary>
        public const string ResetCategpryCache = "Sgr.ResetCategpryCache";

        /// <summary>
        /// 创建并维护数据字典项权限
        /// </summary>
        public const string CreateAndUpdateCategpryItem = "Sgr.CreateAndUpdateCategpryItem";

        /// <summary>
        /// 删除数据字典项权限
        /// </summary>
        public const string DeleteCategpryItem = "Sgr.DeleteCategpryItem";

        /// <summary>
        /// 浏览数据字典项权限
        /// </summary>
        public const string QueryCategpryItem = "Sgr.QueryCategpryItem";

        #endregion 数据字典权限

        #region 行政区划权限

        /// <summary>
        /// 创建并维护行政区划权限
        /// </summary>
        public const string CreateAndUpdateAdministrativeDivision = "Sgr.CreateAndUpdateAdministrativeDivision";

        /// <summary>
        /// 删除行政区划权限
        /// </summary>
        public const string DeleteAdministrativeDivision = "Sgr.DeleteAdministrativeDivision";

        /// <summary>
        /// 浏览行政区划权限
        /// </summary>
        public const string QueryAdministrativeDivision = "Sgr.QueryAdministrativeDivision";

        #endregion 行政区划权限

        /// <summary>
        /// 权限提供者名称
        /// </summary>
        public string ProviderName => "92-数据字典";

        /// <summary>
        /// 获取所有功能权限
        /// </summary>
        public Task<IEnumerable<FunctionPermission>> GetFunctionPermissionsAsync()
        {
            return Task.FromResult(new FunctionPermission[]
            {
                // 数据字典权限
                new(ResetCategpryCache, "数据字典", "重置本地缓存", GrantRoleType.SuperAdmin),
                new(CreateAndUpdateCategpryItem, "数据字典", "创建并维护数据字典项", GrantRoleType.SuperAdmin),
                new(DeleteCategpryItem, "数据字典", "删除数据字典项", GrantRoleType.SuperAdmin),
                new(QueryCategpryItem, "数据字典", "浏览数据字典项", GrantRoleType.SuperAdmin),

                // 行政区划权限
                new(CreateAndUpdateAdministrativeDivision, "行政区划", "创建并维护行政区划", GrantRoleType.SuperAdmin),
                new(DeleteAdministrativeDivision, "行政区划", "删除行政区划", GrantRoleType.SuperAdmin),
                new(QueryAdministrativeDivision, "行政区划", "浏览行政区划", GrantRoleType.SuperAdmin)
            }.AsEnumerable());
        }
    }
}